﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;

namespace WebChamCong
{
    public partial class Generate_Employee : System.Web.UI.Page
    {
        private int owner;
        private DateTime myDate;

        protected void Page_Load(object sender, EventArgs e)
        {
            int localEmp = Convert.ToInt32(Request.QueryString["uid"]);
            DateTime localDate = DateTime.Now;
            Export_Employee(localEmp, localDate);
        }

        private void Export_Employee(int empId, DateTime date)
        {
            int localEmpId = empId;
            DateTime localDate = date;
                        
            ReportDocument rpObject = new ReportDocument();

            rpObject.Load(Server.MapPath("data/rp_employee.rpt"));

            MemoryStream exportToStream = (MemoryStream) rpObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);

            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.BinaryWrite(exportToStream.ToArray());
            Response.End();
        }
    }
}